<!--
 * @Description:: 请补充填写
 * @Version: 1.0
 * @Author: smallWhite
 * @Date: 2023-05-12 20:36:16
 * @LastEditors: smallWhite
 * @LastEditTime: 2023-05-30 14:03:10
 * @FilePath: /siana_admin/src/views/system/stablediffusion/index.vue
-->
<template>
  <el-card>
    <div slot="header">
      <h2>stablediffusion配置
      </h2>
    </div>
    <el-form ref="ruleForm"
      :model="form"
      :rules="rules"
      label-width="180px"
      :label-position="phone?'top':'right'"
      class="demo-ruleForm">

      <el-form-item
        label="stablediffusion地址"
        prop="sdUrl">
        <el-input
          v-model="form.sdUrl"
          :disabled="disabled"
          style="width:100%;max-width: 600px;" />
      </el-form-item>
      <el-form-item
        label="是否开启stablediffusion"
        prop="isOpenSd">
        <el-select
          v-model="form.isOpenSd"
          :disabled="disabled"
          style="width:100%;max-width: 600px;"
          placeholder="请选择是否开启stablediffusion">
          <el-option
            label="关闭"
            :value="0" />
          <el-option
            label="开启"
            :value="1" />
        </el-select>
      </el-form-item>
      <el-form-item
        label="stablediffusion/lora地址"
        prop="sdLoraUrl">
        <el-input
          v-model="form.sdLoraUrl"
          :disabled="disabled"
          style="width:100%;max-width: 600px;" />
      </el-form-item>
      <el-form-item
        v-if="!disabled">
        <el-button
          type="primary"
          @click="handleSubmit()">保存</el-button>
        <el-button
          @click="handleCancel()">取消</el-button>
      </el-form-item>
      <el-form-item v-else>
        <el-button
          type="primary"
          @click="disabled = !disabled">去编辑</el-button>

      </el-form-item>
    </el-form>
  </el-card>
</template>

<script>
export default {
  data() {
    return {
      phone: false,
      form: {
        isOpenSd: 0, // 注册模式  1 账号密码 2 邮箱注册 3 公众号
        sdUrl: '', // gpt请求地址
        sdLoraUrl: '' // 默认注册次数
      },
      disabled: true,
      rules: {
        isOpenSd: [{ required: false, message: '请选择是否开启stablediffusion', trigger: 'blur' }],
        sdUrl: [{ required: false, message: '请输入', trigger: 'blur' }],
        sdLoraUrl: [{ required: false, message: '请输入', trigger: 'blur' }]
      }
    }
  },
  mounted() {
    this.phone = JSON.parse(window.localStorage.getItem('phone'))
    this.getData()
  },
  methods: {
    getData() {
      this.$https('SYSTEMSETTING', {}).then(res => {
        this.form = {
          id: res.data.id,
          isOpenSd: res.data.isOpenSd, // 注册模式  1 账号密码 2 邮箱注册 3 公众号
          sdUrl: res.data.sdUrl, // gpt请求地址
          sdLoraUrl: res.data.sdLoraUrl // stablediffusion lora地址
        }
      })
    },
    handleSubmit() {
      this.$refs.ruleForm.validate(valid => {
        if (valid) {
          this.$https('SYSTEMEDIT', this.form).then(res => {
            if (res.status == 200) {
              this.$message.success('编辑成功！')
              this.disabled = true
            }
          })
        }
      })
    },
    handleCancel() {
      this.form = {
        id: '',
        isOpenSd: 0, // 注册模式  1 账号密码 2 邮箱注册 3 公众号
        sdUrl: '', // gpt请求地址
        sdLoraUrl: ''
      }
      this.getData()
      this.disabled = true
    }
  }
}
</script>

<style>
</style>
